<template>
  <div class="user-container">
    <h2>用户管理</h2>
    <el-card>
      <el-table :data="userList" border style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="姓名" />
        <el-table-column prop="username" label="用户名" />
        <el-table-column prop="email" label="邮箱" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'">
              {{ scope.row.status === 'active' ? '活跃' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" width="150">
          <template #default>
            <el-button size="small" type="primary" icon="Edit" />
            <el-button size="small" type="danger" icon="Delete" />
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import axios from '@/utils/axios'

const userList = ref([])

onMounted(async () => {
  try {
    const res = await axios.get('/api/users')
    userList.value = res.data
  } catch (error) {
    console.error('获取用户列表失败:', error)
  }
})
</script>

<style scoped lang="scss">
.user-container {
  padding: 20px;
}
</style>